package com.free.semantic.model.conceptmodel;

import com.free.semantic.common.RelationItem;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;


@Getter
@Setter
public class RelationItemEntity {

    private Long id;

    private String name;

    private String version;

    private Long semanticNetworkId;

    private String relationStr;

    public RelationItemEntity() {

    }

    public RelationItemEntity(RelationItem relationItem) {
        this.name = relationItem.getName();
        this.version = Integer.toString(relationItem.getVersion());
        this.relationStr = relationItem.toString();
    }


    public RelationItemEntity(Long semanticNetworkId, RelationItem relationItem) {
        this.name = relationItem.getName();
        this.version = Integer.toString(relationItem.getVersion());
        this.semanticNetworkId = semanticNetworkId;
        this.relationStr = relationItem.toString();
    }

    @Override
    public String toString() {
        return relationStr;
    }

    public RelationItem toRelationItem() {
        return RelationItem.parseFromStr(relationStr);
    }

    @Override
    public int hashCode() {
        return toRelationItem().hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return toRelationItem().equals(((RelationItemEntity) obj).toRelationItem());
    }
}